/*
 * Copyright © 2022 XXXXXXXXX
 * @Author: zhangxiang
 * @Date: 2022-08-02 17:54:44
 * @LastEditors: zhangxiang
 * @LastEditTime: 2023-11-04 10:09:54
 * @Description: 应用服务 & 智能调度 相关接口
 * 来源：调度平台cnap-V2.1，应用服务 & 智能调度
 * 前缀 /cnap/api
 *
 */

import request from '@/utils/request'

const PREFIX = '/cnap'

/**
 * @description: 获取应用服务列表
 * @param {*} data
 * @return {*}
 */
export function getAppList(data) {
  return request({
    url: PREFIX + '/api/application/list',
    method: 'post',
    data
  })
}

/**
 * @description: 删除应用
 * @param {*} appId
 * @return {*}
 */
export function deleteApp(appId) {
  return request({
    url: PREFIX + '/api/application/delete/' + appId,
    method: 'delete'
  })
}

/**
 * @description: 更新应用
 * @param {*} data
 * @return {*}
 */
export function updateApp(data) {
  return request({
    url: PREFIX + '/api/application/update',
    method: 'post',
    data
  })
}

/**
 * @description: 初始化上传应用
 * @param {*} data
 * @return {*}
 */
export function initUploadApp(data) {
  return request({
    url: PREFIX + '/api/application/upload',
    method: 'post',
    data
  })
}

/**
 * @description: 上传文件分片
 * @param {*} data
 * @return {*}
 */
export function uploadFilePatch(data) {
  return request({
    url: PREFIX + '/api/file/patch/upload',
    method: 'post',
    data,
    headers: {
      'content-type': 'multipart/form-data'
    },
    timeout: 600 * 1000 // 10分钟超时
  })
}

/**
 * @description: 合并文件分片
 * @param {*} data
 * @return {*}
 */
export function mergeFilePatch(data) {
  return request({
    url: PREFIX + '/api/file/patch/merge',
    method: 'post',
    data
  })
}

/**
 * @description: 查询上传进度
 * @param {*} data
 * @return {*}
 */
export function getFileProgress(id) {
  return request({
    url: PREFIX + '/api/file/progress/' + id,
    method: 'get',
    timeout: 600 * 1000 // 10分钟超时
  })
}

/**
 * @description: 查询待分解应用
 * @param {*} data
 * @return {*}
 */
export function getAppListSplit(data) {
  return request({
    url: PREFIX + '/api/application/list/split',
    method: 'post',
    data
  })
}

/**
 * @description: 微服务分解
 * @param {*} appId
 * @return {*}
 */
export function startSplitMicroService(appId) {
  return request({
    url: PREFIX + '/api/micro-service/split/' + appId,
    method: 'get'
  })
}

/**
 * @description: 查询分解进度
 * @param {*} appId
 * @return {*}
 */
export function getSplitProgress(appId) {
  return request({
    url: PREFIX + '/api/micro-service/progress/' + appId,
    method: 'get'
  })
}

/**
 * @description: 根据应用id查询微服务信息
 * @param {*} appId
 * @return {*}
 */
export function getAppMicroService(appId) {
  return request({
    url: PREFIX + '/api/strategy/list/' + appId,
    method: 'get'
  })
}

/**
 * @description: 添加调度策略
 * @param {*} data
 * @return {*}
 */
export function addScheduleStrategy(data) {
  return request({
    url: PREFIX + '/api/strategy/schedule/add',
    method: 'post',
    data
  })
}

/**
 * @description: 删除调度策略
 * @param {*} id
 * @return {*}
 */
export function deleteScheduleStrategy(data) {
  return request({
    url: PREFIX + '/api/strategy/schedule/delete',
    method: 'post',
    data
  })
}

/**
 * @description: 添加调度策略-更新用户选择集群
 * @param {*} data
 * @return {*}
 */
export function updateUserChoose(data) {
  return request({
    url: PREFIX + '/api/strategy/update/user-choose',
    method: 'post',
    data
  })
}

/**
 * @description: 添加扩缩容策略
 * @param {*} data
 * @return {*}
 */
export function addScaleStrategy(data) {
  return request({
    url: PREFIX + '/api/strategy/scale/add',
    method: 'post',
    data
  })
}

/**
 * @description: 删除扩缩容策略
 * @param {*} id
 * @return {*}
 */
export function deleteScaleStrategy(data) {
  return request({
    url: PREFIX + '/api/strategy/scale/delete',
    method: 'post',
    data
  })
}

/**
 * @description: 根据服务id查询yaml
 * @param {*} appId
 * @return {*}
 */
export function getMicroServiceYaml(appId) {
  return request({
    url: PREFIX + '/api/micro-service/yaml/' + appId,
    method: 'get'
  })
}

/**
 * @description: 微服务验证
 * @param {*} data
 * @return {*}
 */
export function validateMicroService(data) {
  return request({
    url: PREFIX + '/api/micro-service/validate',
    method: 'post',
    data
  })
}

/**
 * @description: 微服务部署
 * @param {*} data
 * @return {*}
 */
export function distributeMicroService(data) {
  return request({
    url: PREFIX + '/api/micro-service/distribute',
    method: 'post',
    data
  })
}

/**
 * @description: 微服务自动化部署
 * @param {*} data
 * @return {*}
 */
export function deployMicroService(data) {
  return request({
    url: PREFIX + '/api/stage/v2/deploy',
    method: 'post',
    data
  })
}

/**
 * @description: 获取应用自动化部署阶段信息
 * @param {*} data
 * @return {*}
 */
export function getDeployStageInfo(appId) {
  return request({
    url: PREFIX + '/api/stage/app/' + appId,
    method: 'get'
  })
}

/**
 * @description: 获取微服务自动化部署阶段信息
 * @param {*} data
 * @return {*}
 */
export function getDeployServiceStageInfo(svcId) {
  return request({
    url: PREFIX + '/api/stage/service/' + svcId,
    method: 'get'
  })
}

/**
 * @description: 获取自动化部署步骤信息
 * @param {*} data
 * @return {*}
 */
export function retryServiceDeploy(svcId) {
  return request({
    url: PREFIX + '/api/stage/retry/service/' + svcId,
    method: 'put'
  })
}

/**
 * @description: 策略部署查询
 * @param {*} data
 * @return {*}
 */
export function getMicroServiceList(data, signal) {
  return request({
    url: PREFIX + '/api/strategy/list/svc',
    method: 'post',
    data,
    signal
  })
}

/**
 * @description: 微服务状态切换
 * @param {*} data
 */
export function microServiceOperation(data) {
  return request({
    url: PREFIX + '/api/strategy/operation',
    method: 'post',
    data
  })
}

/**
 * @description: 更新智能决策
 * @param {*} data
 */
export function updateStrategyIntelligent(data) {
  return request({
    url: PREFIX + '/api/strategy/intelligent/update',
    method: 'post',
    data
  })
}

/**
 * @description: 删除智能决策结果
 * @param {*} data
 */
export function deleteIntelligentDecision(id) {
  return request({
    url: PREFIX + '/api/strategy/intelligent/delete/' + id,
    method: 'delete'
  })
}

/**
 * @description: 获取微服务的跨集群扩缩容记录
 * @param {*} data
 */
export function getClusterScaleInfos(data) {
  return request({
    url: PREFIX + '/deploy/v2/getClusterScaleInfos',
    method: 'post',
    data
  })
}
